package com.aidong.dynamic.biz.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aidong.dynamic.biz.TrnDynamicCommentBiz;
import com.aidong.dynamic.dao.TrnDynamicCommentDao;
import com.aidong.login.dao.MemberInformationDao;

/**
 * 运动圈动态评论service接口实现
 * @author java
 * @version 1.0    
 *  2015.6.2
 */
@Service("trnDynamicCommentBiz")
public class TrnDynamicCommentBizImpl implements TrnDynamicCommentBiz {
	
	private TrnDynamicCommentDao trnDynamicCommentDao;
	
	private MemberInformationDao memberInformationDao;

	@Autowired
	public void setTrnDynamicCommentDao(TrnDynamicCommentDao trnDynamicCommentDao) {
		this.trnDynamicCommentDao = trnDynamicCommentDao;
	}
	
	@Autowired
	public void setMemberInformationDao(MemberInformationDao memberInformationDao) {
		this.memberInformationDao = memberInformationDao;
	}

	/**
	 * 根据动态ID找出该条动态下的所有评论
	 * @param dynamicId
	 * @return
	 */
	@Override
	public List<Map<String, Object>> getCommentByDynamicId(int dynamicId) {
		return trnDynamicCommentDao.getCommentByDynamicId(dynamicId);
	}

	/**
	 * 发表评论
	 * @param dynamicComment
	 */
	@Override
	public void addDynamicComment(Map<String, Object> map) {
		trnDynamicCommentDao.addDynamicComment(map);
		// 增加热度值
		Map<String, Object> currenMap = new HashMap<String, Object>();
		currenMap.put("idongId", map.get("currentIdongId"));
		memberInformationDao.addMemberPopty(currenMap);
		
		Map<String, Object> recipMap = new HashMap<String, Object>();
		recipMap.put("idongId", map.get("currentRecipientId"));
		memberInformationDao.addMemberPopty(recipMap);
		
		Map<String, Object> contentMap = new HashMap<String, Object>();
		contentMap.put("idongId", trnDynamicCommentDao.getIdongIdByDymic(Integer.parseInt(map.get("dynamicId").toString())));
		memberInformationDao.addMemberPopty(contentMap);
	}

	/**
	 * 根据动态ID找出该条动态的评论数
	 * @param dynamicId
	 * @return
	 */
	@Override
	public int getCommentCount(Map<String, Object> map) {
		return trnDynamicCommentDao.getCommentCount(map);
	}
	
	/**
	 * 运动圈评论或者回复删除
	 * @param map
	 */
	@Override
	public void delDynamicComment(Map<String, Object> map) {
		// 减少热度值
		/*Map<String, Object> currenMap = new HashMap<String, Object>();
		currenMap.put("idongId", map.get("currentIdongId"));
		memberInformationDao.delMemberPopty(currenMap);

		Map<String, Object> recipMap = new HashMap<String, Object>();
		recipMap.put("idongId", map.get("currentRecipientId"));
		memberInformationDao.delMemberPopty(recipMap);

		Map<String, Object> contentMap = new HashMap<String, Object>();
		contentMap.put("idongId",
				trnDynamicCommentDao.getIdongIdByDymic(Integer.parseInt(map.get("dynamicId").toString())));
		memberInformationDao.delMemberPopty(contentMap);*/
		
		trnDynamicCommentDao.delDynamicComment(map);
	}
}
